package alan.mybatisPlusDb.module.order.mapper;

import alan.mybatisPlusDb.module.order.entity.TOrder;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class OrderDao {

    @Autowired
    private TOrderMapperMaster tOrderMapperMaster;

    @Autowired
    private TOrderMapperShare tOrderMapperShare;


    /**
     * 因是通过userId进行分库的,所有会执行两条sql
     * @param id
     * @return
     */
    public List<TOrder> getByOrderIdWithShare(Long id){
        return new LambdaQueryChainWrapper<>(tOrderMapperShare).eq(TOrder::getOrderId,id).list();
    }

    public List<TOrder> getByOrderIdWithMaster(Long id){
        return new LambdaQueryChainWrapper<>(tOrderMapperMaster).eq(TOrder::getOrderId,id).list();
    }

    /**
     * 只会执行一条sql
     * @param orderId
     * @param userId
     * @return
     */
    public List<TOrder> getByOrderIdAndUserIdWithShare(Long orderId, Long userId) {
        return new LambdaQueryChainWrapper<>(tOrderMapperShare).eq(TOrder::getOrderId,orderId).eq(TOrder::getUserId,userId).list();
    }
}
